package ;

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import org.qtmo.emu.nes.NES;

/**
 * ...
 * @author Sang Hua Cai
 */

class Main
{

	static function main()
	{
		nesHelper = new NESHelper();
		nesHelper.load("Tank.nes");
	}
	
	private static var nesHelper:NESHelper;
}
class NESHelper
{
	public function new()
	{
		nes = new NES();

		loader = new URLLoader();
		loader.dataFormat = URLLoaderDataFormat.BINARY;
		loader.addEventListener(Event.COMPLETE, loadComplete);
	}

	public function load(path:String):Void
	{
		loader.load(new URLRequest(path));
	}

	private function loadComplete(event:Event):Void
	{
		nes.rom.InsertCartridge(loader.data);
		nes.Reset();
	}

	private var nes:NES;
	private var loader:URLLoader;
}
